package com.hbnu.exercise.mysql;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DatabaseDemo07
{
    public static void main(String[] args)
    {
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;

        try
        {
            connection = DBUtilities.GetConnection();

            String sql = "SELECT * FROM tb_user WHERE password like ?";
            preparedStatement = connection.prepareStatement(sql);

            preparedStatement.setString(1, "%56%");
            resultSet = preparedStatement.executeQuery();

            while (resultSet.next())
            {
                String username = resultSet.getString("username");
                System.out.println(username);
            }
        } catch (SQLException e)
        {
            throw new RuntimeException(e);
        } finally
        {
            DBUtilities.Close(resultSet, preparedStatement, connection);
        }

    }
}
